package com.ygq.train.business.controller;

import com.ygq.train.common.aspect.LogAspect;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class RedisController {
    private final static Logger LOG = LoggerFactory.getLogger(LogAspect.class);
    @Resource
    private RedisTemplate redisTemplate;

    @RequestMapping("/redis/set/{key}/{value}")
    public String Set(@PathVariable String key,@PathVariable String value){
        redisTemplate.opsForValue().set(key,value,3600, TimeUnit.SECONDS);
        LOG.info("key:{},value:{}",key,value);
        return "success";
    }
    @RequestMapping("/redis/get/{key}/")
    public Object Get(@PathVariable String key){
        Object obj = redisTemplate.opsForValue().get(key);
        LOG.info("key:{},value:{}",key,obj);
        return obj;
    }



}
